package com.bjsxt;

import java.awt.*;
import java.awt.event.KeyEvent;

/**
 * @Project: PlaneFight
 * @Author: 陈祖生
 * @Version: 1.0
 * @CreateTime: 2022/7/1 11:46
 * @Description: 飞机模型
 */
public class Plane extends GameObject{

    boolean left,up,right,down;
    boolean live = true;
    public Plane(Image img, int x, int y, int speed) {
        super(img, x, y, speed);
    }

    @Override
    public void drawMyself(Graphics g) {

        if (!live){
            return;
        }
        super.drawMyself(g);

        if (left){
            x-=speed;
        }if (right){
            x+=speed;
        }if (up){
            y-=speed;
        }if (down){
            y+=speed;
        }
    }

    public void addDirection(KeyEvent e){
        switch (e.getKeyCode()) {
            case KeyEvent.VK_LEFT -> left = true;
            case KeyEvent.VK_RIGHT -> right = true;
            case KeyEvent.VK_UP -> up = true;
            case KeyEvent.VK_DOWN -> down = true;
        }
    }

    public void minusDirection(KeyEvent e){
        switch (e.getKeyCode()) {
            case KeyEvent.VK_LEFT -> left = false;
            case KeyEvent.VK_RIGHT -> right = false;
            case KeyEvent.VK_UP -> up = false;
            case KeyEvent.VK_DOWN -> down = false;
        }
    }
}